package com.zhuge_new.Activity;

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.maning.mndialoglibrary.MToast;
import com.zhuge_new.Base.BaseActivity;
import com.zhuge_new.R;
import com.zhuge_new.http.StringDialogCallback;
import com.zhuge_new.share.BaseHttp;
import com.zhuge_new.untils.ActivityStack;
import com.zhuge_new.untils.PreferencesUtils;

/**
 * Created by lenovo on 2018-09-19.
 */

public class CompileActivity extends BaseActivity implements View.OnClickListener {

    private String creditcard;
    private String bank;
    private EditText zd_day;
    private EditText hk_day;
    private EditText mcom_money;
    private Button btn_compit;
    private String creditcardId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.compileactivity);
        Intent intent=getIntent();
        bank = intent.getStringExtra("bank");
        creditcard = intent.getStringExtra("creditcard");
        creditcardId = intent.getStringExtra("creditcardId");
        init_title();
    }

    @Override
    public void init_title() {
        super.init_title();
        TextView tv_titile=findViewById(R.id.tv_nav_title);
        tv_titile.setText("手动添加");
        ImageView iv_back=findViewById(R.id.iv_nav_back);
        TextView card_number=findViewById(R.id.card_number);
        card_number.setText(creditcard);
        TextView issuing_bank=findViewById(R.id.issuing_bank);
        zd_day = findViewById(R.id.zd_day);
        hk_day = findViewById(R.id.hk_day);
        mcom_money = findViewById(R.id.mcom_money);
        btn_compit = findViewById(R.id.btn_compit);
        btn_compit.setOnClickListener(this);
        issuing_bank.setText(bank);
        iv_back.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_nav_back:
                ActivityStack.getScreenManager().popOneActivity(CompileActivity.class);
                break;
            case R.id.btn_compit:
                if (Integer.parseInt(zd_day.getText().toString())>31){
                    MToast.makeTextShort(baseContext,"超过账单日最大设置日期").show();
                }else if (Integer.parseInt(hk_day.getText().toString())>31){
                    MToast.makeTextShort(baseContext,"超过还款日最大设置日期").show();
                }else {
                    submit();
                }
                break;
        }
    }

    private void submit() {
        OkGo.<String>post(BaseHttp.creditcard_edit_sub)
                .tag(this)
                .headers("token", PreferencesUtils.getString(baseContext,"token"))
                .params("creditcardId",creditcardId)
                .params("billDay",zd_day.getText().toString())
                .params("repaymentDay",hk_day.getText().toString())
                .params("billamount",mcom_money.getText().toString())
                .params("cardType","1")
                .execute(new StringDialogCallback(baseContext) {
                    @Override
                    public void onSuccessResponse(Response<String> response, String msg, String msgCode) {

                    }
                });
    }
}
